/*
 * @Author: taosong 2289713738@qq.com
 * @Date: 2023-12-27 16:16:46
 * @LastEditors: taosong 2289713738@qq.com
 * @LastEditTime: 2023-12-27 18:27:01
 * @FilePath: \ele-h5\src\use\useInterVal.ts
 * @Description: 
 * 
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved. 
 */

import { onUnmounted } from "vue"
export const useInterval = (fn: () => void, delay: number) => {
  const timer = setInterval(() => {
    fn()
  }, delay)

  const clear = () => {
    clearInterval(timer)
  }

  onUnmounted(clear)

  return clear
}